package com.lottery.ruok.lottrey.fragment;


import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.bumptech.glide.Glide;
import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.ext.GlideExt;
import com.lottery.ruok.lottrey.retrofitModule.response.ActivityListResponse;
import com.lottery.ruok.lottrey.ui.widget.ActivityInfoItem;

import butterknife.BindView;
import butterknife.ButterKnife;
import utils.StringUtils;

//活动详情Fragment
public class ActivitiesInfoFragment extends BaseFragment {

    @BindView(R.id.activities_info_content)
    ActivityInfoItem activitiesInfo;

    @BindView(R.id.tv_top_big_picture)
    ImageView tvTopBigPicture;

    @BindView(R.id.rl_item_info)
    RelativeLayout rlItemInfo;

    @BindView(R.id.iv_item_info_top)
    ImageView ivItemInfoTop;

    @BindView(R.id.rl_activity_info_all)
    RelativeLayout rlActivityInfoAll;

    private ImageView dailyResetImage;

    private ActivityListResponse.ListBean mData;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle mBundle = getArguments();
        if (mBundle != null) {
            mData = (ActivityListResponse.ListBean) mBundle.getSerializable("data");
        }
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_info_layout, container, false);
        ButterKnife.bind(this, view);
        initView();
        return view;
    }

    private void initView() {
        if (mData == null) {
            return;
        }
        dailyResetImage = activitiesInfo.findViewById(R.id.iv_daily_reset);
        if (!StringUtils.isEmpty(mData.getBanner())){
            Glide.with(this).load(mData.getBanner()).placeholder(R.mipmap.activities_top).error(R.mipmap.activities_top).into(tvTopBigPicture);
        }
        //设置整个背景色
        if (mData.getStyles().getBackground_theme()!=null) {
            rlActivityInfoAll.setBackgroundColor(Color.parseColor(mData.getStyles().getBackground_theme()));
        }

        activitiesInfo.setTopImage(mData.getStyles().getHeader());
        if (mData.getStyles().getBackground_theme() != null) {
            activitiesInfo.setTopbg(mData.getStyles().getBackground_theme());
        }

        activitiesInfo.setData(mData);
        if (mData.getDaily_reset() == 1) {
            dailyResetImage.setVisibility(View.VISIBLE);
            GlideExt.setBackgroundDrawable(getActivity(), mData.getStyles().getDaily_reset(), dailyResetImage, null);
        } else {
            dailyResetImage.setVisibility(View.INVISIBLE);
        }
    }

}
